package com.davidhigenbottam.HeatMap.client;

import com.davidhigenbottam.HeatMap.shared.Results;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.ui.SimplePanel;

public class MapPanel extends SimplePanel {
	JavaScriptObject jsMap;

	public MapPanel() {
		this.getElement().setAttribute("style", "width:"+HeatMap.MAP_WIDTH +";height: "+HeatMap.MAP_HEIGHT);
		this.getElement().setId("themap");
	}

	
//	mapDefaultCenter = LatLng.newInstance(@com.davidhigenbottam.HeatMap.client.HeatMap.DEFAULT_LAT, HeatMap.DEFAULT_LNG);
//	map= new MapWidget(mapDefaultCenter, HeatMap.MAP_DEFAULT_ZOOM);
//	map.setSize(HeatMap.MAP_WIDTH, HeatMap.MAP_HEIGHT);
//	map.setUIToDefault();
//	mapDecoratorPanel.add(map);
//	absolutePanel.add(mapDecoratorPanel,0, HeatMap.UI_TOP_SPACE_HEIGHT);
//	absolutePanel.add(hPanel, 0, 0);
//	
	
	public void createMap(){
		jsMap= nativeCreateMap();
	}
	
	public native JavaScriptObject nativeCreateMap() /*-{
		
		var latlng = new $wnd.google.maps.LatLng(@com.davidhigenbottam.HeatMap.client.HeatMap::DEFAULT_LAT,
		 	@com.davidhigenbottam.HeatMap.client.HeatMap::DEFAULT_LNG);
		var myOptions = {
			zoom : @com.davidhigenbottam.HeatMap.client.HeatMap::MAP_DEFAULT_ZOOM,
			center : latlng,
			mapTypeId : $wnd.google.maps.MapTypeId.ROADMAP
		};
		//$wnd.alert("about to create map...");
		var map = new $wnd.google.maps.Map(this
				.@com.davidhigenbottam.HeatMap.client.MapPanel::getElement()(),
				myOptions);
		//$wnd.alert("created map");
		return map;
	}-*/;

	public KmlLayer createKmlLayer(String url){
		return new KmlLayer(nativeLoadKml(url),jsMap);
	}
	
	public InstitutionsLayer createInstitutionsLayer(Results results){
		return new InstitutionsLayer(results,jsMap);
	}
	public native JavaScriptObject nativeLoadKml(String url) /*-{
		//$wnd.alert("kml url:"+url);
		
		var kmlOptions = {
			map : this.@com.davidhigenbottam.HeatMap.client.MapPanel::jsMap,
			preserveViewport : true
		};

		var kmlLayer = new $wnd.google.maps.KmlLayer(url,kmlOptions);
		//$wnd.alert("kmlLayer.getStatus:"+kmlLayer.getStatus());
		//kmlLayer.setMap(this.@com.davidhigenbottam.HeatMap.client.MapPanel::jsMap);
		//$wnd.alert("set map complete");
		return kmlLayer;
}-*/;	
	

}
